import request from 'utils/request'

/**
 * 获取文章列表
 * @param {*} query 筛选文章参数
 * @returns Promise
 */
export const getArticlesAPI = (query) => {
    return request({
        url: '/mp/articles',
        method: 'get',
        params: query,
    })
}
/**
 * 删除文章
 * @param {*} id
 * @returns
 */
export const deleteArticleByIdAPI = (id) => {
    return request({
        url: `/mp/articles/${id}`,
        method: 'delete',
    })
}

/**
 * 发送请求添加文章
 * @param {*} data
 * @returns
 */
export const addArticleAPI = ({ draft = false, ...data }) => {
    return request({
        url: '/mp/articles?draft=' + draft,
        method: 'post',
        data,
    })
}

/**
 * 获取文章详情信息
 * @param {*} id
 * @returns
 */
export const getArticleById = (id) => {
    return request.get(`/mp/articles/${id}`)
}

/**
* 修改文章的接口
* @param {*} data
* @param {*} draft
* @returns
*/
export const updateArticle = ({ draft = false, ...data }) => {
    return request({
        url: `/mp/articles/${data.id}?draft=${draft}`,
        method: 'PUT',
        data,
    })
}
